package org.jash.sportnews2109.vm

import androidx.lifecycle.MutableLiveData
import org.jash.common.mvvm.BaseViewModel
import org.jash.common.retrofit
import org.jash.sportnews2109.entity.Category
import org.jash.sportnews2109.net.APIService

class HomeViewModel:BaseViewModel() {
    val categoriesLiveData by lazy { MutableLiveData<List<Category>>() }
    val service by lazy { retrofit.create(APIService::class.java)}
    fun loadCategories() {
        progress(service.getCategories()) {
            if (it.code == 0) {
                categoriesLiveData.postValue(it.data)
            } else {
                errorLiveData.postValue(RuntimeException(it.msg))
            }
        }
    }
}